using System;
using System.Collections.Generic;

namespace Firestarter.DB.Schema.Logic
{
    public class CreateTableSqlBuilder_SqlServer : CreateTableSqlBuilder
    {
        public CreateTableSqlBuilder_SqlServer(string tableName): base(tableName)
        {
        }

        protected override string GetColumnAutoIncrementSQL(bool autoIncrementing)
        {
            return autoIncrementing ? "IDENTITY(1,1)" : "";
        }

        protected override string Enclose(string name)
        {
            return string.Format("[{0}]", name);
        }

        /// <summary>
        /// For MySQL: CONSTRAINT `FKNAME` FOREIGN KEY 'FKName' (foreignKeyColumnList) REFERENCES referencedTable(referencedTableColumnList)
        /// For SQL Server need to change to CONSTRAINT [FK_Table_1_Table_2] FOREIGN KEY([fdafdsf])
        /// </summary>
        /// <param name="foreignKeyName"></param>
        /// <param name="parentColumnNameList"></param>
        /// <param name="referencedTableName"></param>
        /// <param name="referencedColumnNameList"></param>
        /// <returns></returns>
        public override void AddForeignKey
            (string foreignKeyName, string parentColumnNameList, string referencedTableName,
             string referencedColumnNameList)
        {
            string createForeignKeyString = string.Format
                ("CONSTRAINT {0} FOREIGN KEY ({1}) REFERENCES {2} ({3})", Enclose(foreignKeyName), EncloseList(parentColumnNameList),
                 Enclose(referencedTableName), EncloseList(referencedColumnNameList));
            ForeignKeys.Add(createForeignKeyString);
            //return this;
        }

    }
}